package com.ruoyi.system.wnjk.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 自动收货队列   //延时队列
 */
@Configuration
public class ReceiveItemMQConfig {

    // 定义交换机名称
    public static final String DELAYED_EXCHANGE_NAME = "delayed_exchange";

    // 定义队列名称
    public static final String AUTO_CONFIRM_QUEUE_NAME = "auto_confirm_queue";

    // 定义路由键
    public static final String AUTO_CONFIRM_ROUTING_KEY = "auto.confirm.key";

    @Bean
    public CustomExchange delayedExchange() {
        // 使用自定义交换机类型 'x-delayed-message' 来支持延迟消息
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(DELAYED_EXCHANGE_NAME, "x-delayed-message", true, false, args);
    }

    @Bean
    public Queue autoConfirmQueue() {
        return new Queue(AUTO_CONFIRM_QUEUE_NAME, true);
    }

    @Bean
    public Binding autoConfirmBinding(Queue autoConfirmQueue, CustomExchange delayedExchange) {
        return BindingBuilder.bind(autoConfirmQueue).to(delayedExchange).with(AUTO_CONFIRM_ROUTING_KEY).noargs();
    }
}
